﻿Imports System.Resources
Imports System.Threading
Imports Biz
Imports BLL
Imports DevComponents.DotNetBar


Public Class ctrlEdicionGrupoAsegurables
    Private _llamador As frmMainMetro
    Private _bAlta As Boolean
    Private _oFamilia As cFamilia
    Private _RM As ResourceManager


    Public Sub SetIdioma()

        _RM = New ResourceManager("UI.Idiomas", System.Reflection.Assembly.GetExecutingAssembly)

        btnAceptar.Text = _RM.GetString("btnAceptar")
        btnCancelar.Text = _RM.GetString("btnCancelar")

    End Sub

    Public Property Llamador() As frmMainMetro
        Get
            Return _llamador
        End Get
        Set(value As frmMainMetro)
            _llamador = value
        End Set
    End Property

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
    End Sub

    Private Function ValidarForm() As Boolean
        Dim bValido As Boolean = True

        If lblCodigoGrupo.Text.Trim = "" Then bValido = False
        If txtDescripcion.Text.Trim = "" Then bValido = False

        ValidarForm = bValido

    End Function

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
        Dim oAux As cFamilia


        If ValidarForm() Then
            oAux = New cFamilia
            oAux.Fam_Codigo = lblCodigoGrupo.Text
            oAux.Fam_Descrip = txtDescripcion.Text

            Try
                GestorFamilia.Instance.Editar(oAux)
                GestorBitacora.Instance.Loguear(New cBitacora_Usuario(AppCurrentState.UsuarioLogueado.Usu_Legajo, Utils.Enumeradores.Bitacora.SegFamiliaModificacion))

            Catch ex As Excepciones.FamiliaFalloEditar
                Main.ManejarExcepcion(ex)
            Catch ex As Exception
                Main.ManejarExcepcion(ex)
            End Try

            _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
            _llamador.RefrescarGrillas()
        Else
            lblMensajes.Text = "Complete todos los datos requeridos..."
        End If

    End Sub

    Public Sub MostrarParaEdicion(oFamilia As cFamilia)

        lblTituloForm.Text = "Editar grupo de asegurables"
        lblMensajes.Text = ""

        _oFamilia = oFamilia

        LlenarForm(oFamilia)

        txtDescripcion.Focus()

    End Sub

    Private Sub LlenarForm(oAux As cFamilia)

        If Not oAux Is Nothing Then
            lblCodigoGrupo.Text = oAux.Fam_Codigo
            txtDescripcion.Text = oAux.Fam_Descrip

        Else
            lblCodigoGrupo.Text = ""
            txtDescripcion.Text = ""
        End If

    End Sub
End Class
